﻿'   FAHWatch7 FirstRun
'   Copyright (c) 2010 Marvin Westmaas ( MtM / Marvin_The_Martian )
'
'   This program is free software: you can redistribute it and/or modify
'   it under the terms of the GNU General Public License as published by
'   the Free Software Foundation, either version 3 of the License, or
'   (at your option) any later version.
'
'   This program is distributed in the hope that it will be useful,
'   but WITHOUT ANY WARRANTY; without even the implied warranty of
'   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'   GNU General Public License for more details.
'
'   You should have received a copy of the GNU General Public License
'   along with this program.  If not, see <http://www.gnu.org/licenses/>.
Public Class frmFirstRun
    'Won't do = Read fahcontrol DB and add remote clients? 

    Private Sub frmFirstRun_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            txtLocalClient.Text = System.Environment.MachineName
            'Change later
            cmbDefaultView.Text = cmbDefaultView.Items(0).ToString
            cmbDefaultView.Enabled = False
            '
            txtPsummary.Text = mySettings.DefaultSummary
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub cmdRemote_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            rClients.ShowForm(Me)
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub
    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        Try
            Dim rval As MsgBoxResult = MsgBox("Canceling the configuration process now will require you to configure FAHWatch7 upon the next exectution. Are you sure?", vbOKCancel, "Cancel configuration")
            If rval = vbOK Then
                'Delete db file
                sqData.Close()
                If My.Computer.FileSystem.FileExists(Application.StartupPath & "\FAHWatch7.db") Then My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\FAHWatch7.db", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
                End
            End If
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub cmdOK_Click(sender As System.Object, e As System.EventArgs) Handles cmdOK.Click
        Try
            mySettings.DefaultSummary = txtPsummary.Text
            mySettings.LocalClientName = txtLocalClient.Text
            mySettings.LiveView = chkLive.Checked
            mySettings.DefaultView = cmbDefaultView.Text
            mySettings.SaveSettings()
            LogParser.Init(txtLocalClient.Text)
            Me.Hide()
            Dim frmR As New frmRemoteClients
            frmR._IsFirstRun = True
            frmR.ShowDialog()
            Me.DialogResult = Windows.Forms.DialogResult.OK
            Me.Close()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub chkLive_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles chkLive.CheckedChanged
        Try
            cmbDefaultView.Enabled = chkLive.Checked
        Catch ex As Exception
            LogWindow.WriteError(ex.Message, Err)
        End Try
    End Sub

    Private Sub txtLocalClient_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtLocalClient.KeyUp
        'If e.KeyData = Keys.Subtract Then
        '    e.SuppressKeyPress = True
        '    txtLocalClient.AppendText("_")
        'ElseIf e.KeyData = Keys.Separator Then
        '    e.SuppressKeyPress = True
        'End If
    End Sub

    Private Sub txtLocalClient_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtLocalClient.TextChanged
        Try
            Dim iSelStart As Int32 = txtLocalClient.SelectionStart
            txtLocalClient.Text = txtLocalClient.Text.Replace("-", "_").Replace("'", "").Trim
            txtLocalClient.SelectionStart = iSelStart
        Catch ex As Exception

        End Try
    End Sub
End Class